package com.hngates.project.controller;

import java.util.List;

import com.hngates.common.utils.ShiroUtils;
import com.hngates.project.domain.ServiceContract;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.hngates.common.annotation.Log;
import com.hngates.common.enums.BusinessType;
import com.hngates.project.domain.SubcontractorSpecific;
import com.hngates.project.service.ISubcontractorSpecificService;
import com.hngates.common.core.controller.BaseController;
import com.hngates.common.core.domain.AjaxResult;
import com.hngates.common.utils.poi.ExcelUtil;
import com.hngates.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 分包单位具体信息Controller
 * 
 * @author ruoyi
 * @date 2022-06-24
 */
@Controller
@RequestMapping("/project/subcontractorSpecific")
public class SubcontractorSpecificController extends BaseController
{
    private String prefix = "project/subcontractorSpecific";

    @Autowired
    private ISubcontractorSpecificService subcontractorSpecificService;

    @RequiresPermissions("project:subcontractorSpecific:view")
    @GetMapping()
    public String subcontractorSpecific()
    {
        return prefix + "/subcontractorSpecific";
    }

    /**
     * 查询分包单位具体信息列表
     */
    @RequiresPermissions("project:subcontractorSpecific:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SubcontractorSpecific subcontractorSpecific)
    {
        startPage();
        List<SubcontractorSpecific> list = subcontractorSpecificService.selectSubcontractorSpecificList(subcontractorSpecific);
        return getDataTable(list);
    }

    /**
     * 导出分包单位具体信息列表
     */
    @RequiresPermissions("project:subcontractorSpecific:export")
    @Log(title = "分包单位具体信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SubcontractorSpecific subcontractorSpecific)
    {
        List<SubcontractorSpecific> list = subcontractorSpecificService.selectSubcontractorSpecificList(subcontractorSpecific);
        ExcelUtil<SubcontractorSpecific> util = new ExcelUtil<SubcontractorSpecific>(SubcontractorSpecific.class);
        return util.exportExcel(list, "分包单位具体信息数据");
    }

    /**
     * 下载模板
     *
     * @return
     */
    @RequiresPermissions("project:subcontractorSpecific:view")
    @GetMapping("/importTemplate")
    @ResponseBody
    public AjaxResult importTemplate() {
        ExcelUtil<SubcontractorSpecific> util = new ExcelUtil<>(SubcontractorSpecific.class);
        return util.importTemplateExcel("分包单位具体信息数据");
    }

    /**
     *
     * @param file
     * @param updateSupport
     * @return
     * @throws Exception
     */
    @RequiresPermissions("project:subcontractorSpecific:import")
    @PostMapping("/importSubcontractorSpecific")
    @ResponseBody
    public AjaxResult importSubcontractorSpecific(MultipartFile file, boolean updateSupport) throws Exception{
        ExcelUtil<SubcontractorSpecific> util = new ExcelUtil<>(SubcontractorSpecific.class);
        List<SubcontractorSpecific> subcontractorSpecificList = util.importExcel(file.getInputStream(), 1);
        String operName = ShiroUtils.getSysUser().getLoginName();
        String message = subcontractorSpecificService.importSubcontractorSpecific(subcontractorSpecificList, updateSupport, operName);
        return AjaxResult.success(message);
    }


    /**
     * 新增分包单位具体信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存分包单位具体信息
     */
    @RequiresPermissions("project:subcontractorSpecific:add")
    @Log(title = "分包单位具体信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SubcontractorSpecific subcontractorSpecific)
    {
        return toAjax(subcontractorSpecificService.insertSubcontractorSpecific(subcontractorSpecific));
    }

    /**
     * 修改分包单位具体信息
     */
    @RequiresPermissions("project:subcontractorSpecific:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        SubcontractorSpecific subcontractorSpecific = subcontractorSpecificService.selectSubcontractorSpecificById(id);
        mmap.put("subcontractorSpecific", subcontractorSpecific);
        return prefix + "/edit";
    }

    /**
     * 修改保存分包单位具体信息
     */
    @RequiresPermissions("project:subcontractorSpecific:edit")
    @Log(title = "分包单位具体信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SubcontractorSpecific subcontractorSpecific)
    {
        return toAjax(subcontractorSpecificService.updateSubcontractorSpecific(subcontractorSpecific));
    }

    /**
     * 删除分包单位具体信息
     */
    @RequiresPermissions("project:subcontractorSpecific:remove")
    @Log(title = "分包单位具体信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(subcontractorSpecificService.deleteSubcontractorSpecificByIds(ids));
    }
}
